//
//  CreatOrderVC.m
//  ZPSALE
//
//  Created by fei on 14-8-13.
//  Copyright (c) 2014年 self. All rights reserved.
//

#import "CreatOrderVC.h"
#import "PaymentWayTVC.h"
#import "InvoiceTypeTVC.h"
#import "OrderProductListTVC.h"
#import "MyAddressVC.h"

@interface CreatOrderVC ()
@property (nonatomic,copy) NSString *userNameStr;
@property (nonatomic,copy) NSString *userPhoneStr;
@property (nonatomic,copy) NSString *userAddrStr;
@property (nonatomic,copy) NSString *payWayStr;
@property (nonatomic,copy) NSString *payWayId;
@property (nonatomic,copy) NSString *shippingTimeStr;
@property (nonatomic,copy) NSString *invoiceTypeStr;
@property (nonatomic,copy) NSString *invoiceDetailStr;
@property (nonatomic,copy) NSString *invoiceHeaderStr;
@property (nonatomic,copy) NSString *totalPirceStr;
@property (nonatomic,copy) NSString *discountPirceStr;

@end

@implementation CreatOrderVC



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"确认订单";
    self.orderTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderTableView.bounds.size.width, 0.01f)];
}

#pragma mark  UITableView Datasource 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 7;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 77;
    }
    if (indexPath.section == 3) {
        return 100;
    }
    if (indexPath.section == 6) {
        return 73;
    }
    return 44;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
//    addresscell	用户名 100  地址 101
//    invoicecell  类型 101 明细 102  抬头 103
//    reusecell  title 100 detail 101
//    textcell  textView 100
//    pricecell  price  101
    switch (indexPath.section) {
        case 0:
        {
            cell = nil;
            cell = [tableView dequeueReusableCellWithIdentifier:@"addresscell" forIndexPath:indexPath];
            UILabel *nameLabel = (UILabel *)[cell.contentView viewWithTag:100];
            UILabel *infoLabel = (UILabel *)[cell.contentView viewWithTag:101];
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@   %@",_userNameStr,_userPhoneStr]];
            [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(str.length-_userPhoneStr.length, _userPhoneStr.length)];
            nameLabel.attributedText = str;
            infoLabel.text = _userAddrStr;
        }
            break;
        case 1:
        {
            cell = nil;
            cell = [tableView dequeueReusableCellWithIdentifier:@"reusecell" forIndexPath:indexPath];
            UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag:100];
            UILabel *detailLabel = (UILabel *)[cell.contentView viewWithTag:101];
            titleLabel.text = @"支付方式";
            detailLabel.text = [self isStringHasDetails:_payWayStr] ? _payWayStr:@"请选择";
        }
            break;
        case 2:
        {
            cell = nil;
            cell = [tableView dequeueReusableCellWithIdentifier:@"reusecell" forIndexPath:indexPath];
            UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag:100];
            UILabel *detailLabel = (UILabel *)[cell.contentView viewWithTag:101];
            titleLabel.text = @"配送时间";
            detailLabel.text = [self isStringHasDetails:_shippingTimeStr] ? _shippingTimeStr:@"请选择";
        }
            break;
        case 3:
        {//    invoicecell  类型 101 明细 102  抬头 103
            cell = nil;
            cell = [tableView dequeueReusableCellWithIdentifier:@"invoicecell" forIndexPath:indexPath];
            UILabel *typeLabel = (UILabel *)[cell.contentView viewWithTag:101];
            UILabel *detailLabel = (UILabel *)[cell.contentView viewWithTag:102];
            UILabel *headerLabel = (UILabel *)[cell.contentView viewWithTag:103];
            
            typeLabel.text = [self isStringHasDetails:_invoiceTypeStr] ? _invoiceTypeStr:@"请选择";
            detailLabel.text = [self isStringHasDetails:_invoiceDetailStr] ? _invoiceDetailStr:@"请选择";
            headerLabel.text = [self isStringHasDetails:_invoiceHeaderStr] ? _invoiceHeaderStr:@"请选择";
            
            
        }
            break;
        case 4:
        {//    textcell  textView 100
            cell = nil;
            cell = [tableView dequeueReusableCellWithIdentifier:@"textcell" forIndexPath:indexPath];
            UITextView *textView = (UITextView *)[cell.contentView viewWithTag:100];
            textView.delegate = self;
        }
            break;
        case 5:
        {
            cell = nil;
            cell = [tableView dequeueReusableCellWithIdentifier:@"reusecell" forIndexPath:indexPath];
            UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag:100];
            UILabel *detailLabel = (UILabel *)[cell.contentView viewWithTag:101];
            titleLabel.text = @"查看商品清单";
            detailLabel.text = @"";
        }
            break;
        case 6:
        {//pricecell  price  101
            cell = nil;
            
            cell = [tableView dequeueReusableCellWithIdentifier:@"pricecell" forIndexPath:indexPath];
            UILabel *priceLabel = (UILabel *)[cell.contentView viewWithTag:101];
            UILabel *discountLabel = (UILabel *)[cell.contentView viewWithTag:102];
            priceLabel.text = [self isStringHasDetails:_totalPirceStr] ? _totalPirceStr:@"¥ 0";
            discountLabel.text = [self isStringHasDetails:_discountPirceStr] ? _discountPirceStr:@"¥ 0";
        }
            break;
        default:
            break;
    }
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark -- UITableView Delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //0 地址  1-支付方式 2-配送时间按 3-发票  4-订单备注 5-商品清单 6-订单总金额
    switch (indexPath.section) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            
        }
            break;
        case 2:
        {
            
        }
            break;
        case 3:
        {
            
        }
            break;
        case 4:
        {
            
        }
            break;
        case 5:
        {
            
        }
            break;
        case 6:
        {
            
        }
            break;
            
        default:
            break;
    }
}
#pragma UITextView delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField {
    [_orderTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:4] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(BOOL)isStringHasDetails:(NSString *)str {
    BOOL has;
    
    if ([str isEqual:[NSNull null]] || str.length == 0) {
        has = NO;
    } else
        has = YES;
    return has;
}


@end
